package study.designpattern.memento;

public class Originator {
    private String state;
    
    public void setState(String state){
        System.out.println("Originator: Setting state to " + state);
        this.state = state;
    }
    
    public Memento saveToMemento(){
        System.out.println("Originator: Saving to Memento");
        return new Memento(state);
    }
    
    public void restoreFromMemento(Memento memento){
        this.state = memento.getSavedState();
        System.out.println("Originator: State after restoring from Memento: "+ state);
    }
    
    
    public static class Memento {
        private String state;

        public Memento(String state) {
            super();
            this.state = state;
        }
        
        public String getSavedState(){
            return state;
        }
    }
}
